import {RouteRecordRaw} from "vue-router";
import Login from "../pages/login.vue";
import Home from "../pages/home/index.vue";
import BasicLayout from "../components/basicLayout/index.vue";

interface ParentConfig {
  title: string;
  name: string;
  fullPath: string;
}

interface RouteMetaModel {
  title: string;
  parents?: ParentConfig[];
  isMenuGroup?: true;
  // fullPath: string; 用于菜单导航
  icon: string;
}

type RouteRecordModel = RouteRecordRaw & {
  meta?: RouteMetaModel;
}

const routes: RouteRecordModel[] = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  /* 
  {
    path: '/home',
    component: () => import('../pages/home/index.vue').then(home => {
      return {
        render() {
          return h(BasicLayout, null, () => h(home.default));
        }
      }
    }),
    meta: {
      title: '首页',
      name: 'Home'
    }
  },
  */
  {
    path: '/home',
    component: BasicLayout,
    meta: {
      title: '首页',
      name: 'Home',
      icon: 'Menu'
    },
    children: [
      {
        path: '',
        name: 'Home',
        component: Home
      },
    ]
  },

  {
    path: '/system-manage',
    component: BasicLayout,
    meta: {
      title: '系统管理',
      name: 'SystemManage',
      isMenuGroup: true,
      icon: 'Menu'
    },
    children: [
      {
        path: 'user-manage',
        name: 'UserManage',
        component: () => import('../pages/systemManage/userManage/index.vue'),
        meta: {
          title: '用户管理',
          icon: 'Menu',
          parents: [
            {
              title: '系统管理',
              name: 'SystemManage',
              fullPath: '/system-manage'
            }
          ]
        }
      },
      {
        path: 'role-manage',
        name: 'RoleManage',
        component: () => import('../pages/systemManage/roleManage/index.vue'),
        meta: {
          title: '角色管理',
          icon: 'Menu',
          parents: [
            {
              title: '系统管理',
              name: 'SystemManage',
              fullPath: '/system-manage'
            }
          ]
        }
      },
      {
        path: 'menu-manage',
        name: 'MenuManage',
        component: () => import('../pages/systemManage/menuManage/index.vue'),
        meta: {
          title: '菜单管理',
          icon: 'Menu',
          parents: [
            {
              title: '系统管理',
              name: 'SystemManage',
              fullPath: '/system-manage'
            }
          ]
        }
      },
      {
        path: 'log-manage',
        meta: {
          title: '日志管理',
          name: 'LogManage',
          icon: 'Menu',
          isMenuGroup: true
        },
        children: [
          {
            path: 'operate-log',
            name: 'OperateLog',
            component: () => import('../pages/systemManage/logManage/operateLog.vue'),
            meta: {
              title: '操作日志',
              icon: 'Menu',
              parents: [
                {
                  title: '系统管理',
                  name: 'SystemManage',
                  fullPath: '/system-manage'
                },
                {
                  title: '日志管理',
                  name: 'LogManage',
                  fullPath: '/system-manage/log-manage'
                }
              ]
            }
          },
          {
            path: 'login-log',
            name: 'LoginLog',
            component: () => import('../pages/systemManage/logManage/loginLog.vue'),
            meta: {
              title: '登录日志',
              icon: 'Menu',
              parents: [
                {
                  title: '系统管理',
                  name: 'SystemManage',
                  fullPath: '/system-manage'
                },
                {
                  title: '日志管理',
                  name: 'LogManage',
                  fullPath: '/system-manage/log-manage'
                }
              ]
            }
          },
          {
            path: '',
            redirect: '/system-manage/log-manage/operate-log'
          }
        ]
      },
      {
        path: '',
        redirect: '/system-manage/user-manage'
      }
    ]
  },

  /* {
    path: '//www.baidu.com',
    component: BasicLayout,
    meta: {
      title: '官网',
      name: 'gw'
    },
  }, */

  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/home'
  }
  // { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
];

export {
  RouteMetaModel,
  ParentConfig,
  RouteRecordModel,
  routes
}
